package com.kaishengit.service;

import java.util.List;


import com.kaishengit.dao.EmployeeProjectDao;
import com.kaishengit.dao.ProjectDao;
import com.kaishengit.entity.EmployeeProject;
import com.kaishengit.entity.Project;
import com.kaishengit.util.DateUtil;
import com.kaishengit.util.PKUtil;


public class ProjectService {
	private ProjectDao dao = new ProjectDao();

	public List<Project> findById(String id) {
		
		return dao.findById(id);
	}

	public void save(String name, String desc, String manger,String workers) {
		String id = PKUtil.getPK();
		String createtime = DateUtil.getNow();
		Project p = new Project();
		p.setCreatetime(createtime);
		p.setDesc(desc);
		p.setId(id);
		p.setName(name);
		dao.save(p);
		EmployeeProject ep = new EmployeeProject();
		ep.setEmployeeid(manger);
		ep.setProjectid(id);
		ep.setRole("manger");
		EmployeeProjectDao epDao = new EmployeeProjectDao();
		epDao.save(ep);
		String[] workid = workers.split(",");
		for(String i : workid){
			EmployeeProject ep2 = new EmployeeProject();
			ep2.setEmployeeid(i);
			ep2.setProjectid(id);
			ep2.setRole("worker");
			epDao.save(ep2);
		}
	}

	public EmployeeProject findById(String id, String projectid) {
		EmployeeProjectDao dao = new EmployeeProjectDao();
		return dao.findById(id,projectid);
	}


	
}
